<!DOCTYPE html>
<html class="x-admin-sm">

<head>
<meta charset="UTF-8">
<title>项目列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<script src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>

<body>
	<div class="x-nav">
		<span class="layui-breadcrumb"> <a href="index.html">首页</a> <a href="">管理员</a>
			<a> <cite>项目列表</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			onclick="location.reload()" title="刷新"> <i
			class="layui-icon layui-icon-refresh" style="line-height: 30px"></i>
		</a>
	</div>
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-card-body ">
						<form class="layui-form layui-col-space5">
							<div class="layui-inline layui-show-xs-block">
								<input class="layui-input" autocomplete="off" placeholder="项目名"
									name="name" id="name">
							</div>
							<div class="layui-inline layui-show-xs-block">
								<input class="layui-input" autocomplete="off" placeholder="分类"
									name="category" id="category">
							</div>

							<div class="layui-inline layui-show-xs-block">
								<button class="layui-btn" lay-submit lay-filter="sreach">
									<i class="layui-icon">&#xe615;</i>
								</button>
							</div>
						</form>
					</div>
					<div class="layui-card-body">
						<table id="projectList" lay-filter="projectList"></table>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
	<script type="text/html" id="toolbarList">
        <div class = "layui-btn-container" > 
			<button class = "layui-btn layui-btn-sm" lay-event = "addNewUser" >
			<i class="layui-icon">&#xe654;</i>
			 添加专家
			 </button>
			<button class = "layui-btn layui-btn-sm" lay-event = "delBatch" > 批量删除 </button>
            <!--
            <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button > 
            <button class = "layui-btn layui-btn-sm" lay-event = "isAll" > 验证是否全选</button>-->
        </div > 
    </script>
    <!--操作-->
	<script type="text/html" id="newsListBar">
		<a class="layui-btn layui-btn-xs" id="edit" lay-event="edit">编辑</a>
		<a class="layui-btn layui-btn-xs layui-btn-danger" id="del" lay-event="del">删除</a>

		<a class="layui-btn layui-btn-xs layui-btn-primary" id="look" lay-event="look">详情</a>
		<a class="layui-btn layui-btn-xs layui-btn-primary" id="workhistory" lay-event="look">工作历史</a>
		<a class="layui-btn layui-btn-xs layui-btn-primary" id="enrollProj" lay-event="look">参与项目</a>
		<a class="layui-btn layui-btn-xs layui-btn-primary" id="exportToWord" target="_blank" lay-event="exportToWord">导出为word</a>
	</script>

<script>
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        //项目列表
        var tableIns = table.render({
            elem: '#projectList',
            url :'projectsSearch',
            cellMinWidth : 95,
            page : true,
            height : "full-125",
            limit : 10,
            limits : [10,15,20,25],
            id : "projectListTable",
			toolbar:"#toolbarList",
            cols : [[
                {type: "checkbox", fixed:"left", width:50},
                {field: 'id', title: '编号', width:60, align:"center"},
                {field: 'projectName', title: '名称', align:'center'},
                {field: 'projectCategory', title: '类型', align:'center'},
                {field: 'departmentName', title: '采购部门',  align:'center'},
                {field: 'budget', title: '采购预算(万元)', align:'center'},
                {field: 'address', title: '开标地点', align:'center', minWidth:110},
                {field: 'isEvaluated', title: '项目状态', align:'center', minWidth:110,templet:function (data) {
						if(data.isEvaluated=="1")
						    return "待抽签";
						else if(data.isEvaluated=="2"){
                            return "随机抽签中";
						}
                        else if(data.isEvaluated=="3"){
                            return "补抽中";
                        }
                        else if(data.isEvaluated=="4"){
                            return "抽签已完成";
                        }else if(data.isEvaluated=="5"){
                            return "登记成功";
                        }else{//
                            return data.isEvaluated;
						}
                    }},
                {field: 'openDate', title: '开标时间', align:'center', minWidth:140},
                /* {field: 'announceDate', title: '公告时间', align:'center', minWidth:110},
                 {field: 'openDate', title: '开标时间', align:'center', minWidth:110},

                 {field: 'dealDate', title: '开标公告时间', align:'center', minWidth:110},*/
                /* {field: 'dealCompany', title: '成交单位', align:'center', minWidth:110},
                 {field: 'settlePrice', title: '成交价格', align:'center', minWidth:110},*/
                {title: '操作', minWidth:470,fixed:"right",align:"left", templet:function(data){
                        var str='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="look">详情</a>';
                        str+='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="professor">专家</a>';
                        str+='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="exportToWord">导出为word</a>';

                        if(data.status==1)
                            return str;

                        if(data.isEvaluated=='1'||data.isEvaluated=='待抽签'){
                          str+='<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
                          str+='<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>';
                        }

                        var array=['1','2','3','待抽签','随机抽签中','补抽中'];

                        var sin=array.some(function(elt) {
                            return elt==data.isEvaluated;
                        });
                        //alert(sin);
                        if(sin){
                            str+='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="selectProfessor">抽取专家</a>';
                        }
                        var dateStr=new Date().toLocaleDateString();
                        if((data.isEvaluated=='4'||data.isEvaluated=='抽签已完成') &&data.openDate<=dateStr){
                            str+='<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="inputSettle">中标信息</a>';
                        }
                        return str;
                    }}
                /*{title: '操作', width:250, templet:'#projectListBar',fixed:"right",align:"center"}*/
            ]]
        });


        //搜索【此功能需要后台配合】
        form.on("submit(sreach)",function(data){

            table.reload("projectListTable", {
                page : {
                    curr : 1
                    //重新从第 1 页开始
                },
                where : {
                    name : $("input[name=name]").val(), //搜索的关键字
                    category : $("input[name=category]").val()
                }
            });
            return false;
        });

        //添加项目
        function addProject(edit){

        }
        $(".addProject_btn").click(function(){
            addProject();
        })
        //项目详情
        function look(edit){

        }
//查询专家列表
        function search(edit){

            var index = layui.layer.open({
                title : "查询专家",
                type : 2,
                content : "searchProfessor.html?"+edit.id,
                success: function(layero, index){
                    console.log(layero, index);
                }
            });
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize", function() {
                try{
                    layui.layer.full(index);
                }catch(e){}
            })
        }
        //批量删除
        $(".delAll_btn").click(function(){

        })

        function selectProfessor(data){
            window.sessionStorage.setItem("project",JSON.stringify(data));
            xadmin.open('抽取专家','selectProfessor.html?'+data.id,600,400,true);

        }
        function inputSettle(data){
            //偷懒了，最好open一个窗口完成填写
            layer.prompt({formType:2,title:"请输入中标企业信息",area: ['300px', '240px'],btn:['确认','关闭']
			,content:('<label>中&nbsp;&nbsp;标&nbsp;&nbsp;企&nbsp;&nbsp;业</label><input name="dealCompany" id="dealCompany"/><br/><label>中标价(万元)</label><input type="number" id="settlePrice" name="settlePrice"/>')
            ,yes:function (index,layero) {
					//alert(JSON.stringify(layero)+"????????????"+layero.find("#dealCompany").val());
					var c=layero.find("#dealCompany").val();
					var money=layero.find("#settlePrice").val();
					alert(c+"><>>>>"+money+"万元：：");
					$.post("inputSettle",{dealCompany:c,settlePrice:money,projid:data.id},function(d){
					    alert(JSON.stringify(d));
						if(d.result){
						    //location.reload();
							//table.reload("projectListTable");
                            layer.msg("请刷新查看效果!");
						}else{
						    layer.msg("修改失败!");
						}
					});
					layer.close(index);
                }
                ,no:function (index,layero) {
                    layer.close(index);
                }
            });
		}
        //列表操作
        table.on('tool(projectList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;//行

			alert(layEvent);

            if(layEvent === 'selectProfessor'){
                var array=['1','2','3','待抽签','随机抽签中','补抽中'];
                var sin=array.some(function(elt) {
                    return elt==data.isEvaluated;
                });
                if(sin){
                    selectProfessor(data);
                }
            }
            else if(layEvent === 'edit'){ //编辑
                addProject(data);
            } else if(layEvent === 'del'){ //删除
                layer.confirm('确定删除选中的项目？', {
                    icon : 3,
                    title : '提示信息'
                }, function(index) {
                    $.getJSON(_BASE_ + "project/del", {
                        id : data.id
                    }, function(d) {
                        if (d.code) {
                            tableIns.reload();
                            layer.close(index);
                        } else {
                            layer.alert("删除失败");
                        }
                    });
                })
            } else if(layEvent === 'look'){ //预览
                look(data);
            }
            else if(layEvent === 'professor'){
                search(data);
            } else if(layEvent === 'inputSettle'){
                inputSettle(data);
            }
        });

    })
</script>

</html>